
$(function() {	
	Tip.emp('员工');
});

var Business = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},			
			
			"添加": function() {				
				if (!confirm("确认是否添加？")) {
					return false;
				}				
	
				var form = $("#form_add")[0];
	
				var body = { };
				body.emp = form.emp.value;
				body.date = form.date.value;
				body.expect = form.expect.value;
				body.type = form.type.value;
				body.name = form.name.value;
				body.opinion1 = form.opinion1.value;
				body.opinion2 = form.opinion2.value;
				
				body.content = form.content.value;
				
				// alert($.toJSON(body));
					
				$(this).dialog("close");
	
				$.post('emp.php?do=Business.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},

	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var a1 = ['编辑信息', 'url', 'Business.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];
		var a3 = ['复制信息', 'url', 'Business.dialog_copy_', '650x400'];
		
		var c1 = 'emp.php?do=Business.edit&id=' + id;
		var c2 = 'emp.php?do=Business.view&id=' + id;
		var c3 = 'emp.php?do=Business.copy&id=' + id;
		
		var c4 = 'emp.php?do=Business.upload&id=' + id;
		var a4 = ['上传附件', 'url', 'Common.dialog_upload', '600x420'];
		
		// 等待
		if (status == '2' || status == '3') {
			var d1 = 'emp.php?do=Business.replier&id=' + id;
			var b1 = ['指定负责人', 'url', 'Business.dialog_replier', '650x400'];
			
			var s = d1 + ", " + c1 + ", " + c2 + ", " + c4;

			return popup(e, [b1, a1, a2, a4], s);
		}
		
		var s = c1 + ", " + c2 + ", " + c3 + ", " + c3;

		popup(e, [a1, a2, a3, a4], s);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('emp.php?do=Emp.audit&item=79', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_edit")[0];
			
						var body = {};
						body.id = form.id.value;
						body.emp = form.emp.value;
						body.date = form.date.value;
						body.expect = form.expect.value;
						body.type = form.type.value;
						body.name = form.name.value;
						body.opinion1 = form.opinion1.value;
						body.opinion2 = form.opinion2.value;
						
						body.finish = form.finish.value;
						body.reply = form.reply.value;
						body.replier = form.replier.value;
						
						body.content = form.content.value;
						body.status = form.status.value;
			
						$(this).dialog("close");
			
						var url = 'emp.php?do=Business.editPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
	
				var body = {};
				body.id = form.id.value;
				body.emp = form.emp.value;
				body.date = form.date.value;
				body.expect = form.expect.value;
				body.type = form.type.value;
				body.name = form.name.value;
				body.opinion1 = form.opinion1.value;
				body.opinion2 = form.opinion2.value;
				
				body.content = form.content.value;
	
				$(this).dialog("close");
	
				var url = 'emp.php?do=Business.addPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_replier: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}				

				var form = $("#form_edit")[0];
				
				var body = {};
				body.id = form.id.value;
				body.replier = form.replier.value;
				
				$(this).dialog("close");

				var url = 'emp.php?do=Business.replierPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	}
};
